<template>
  <el-menu
    router
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    default-active="1"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
  >
    <h3>{{ isCollapse ? "后台" : "通用后台管理系统" }}</h3>
    <el-menu-item
      :route="p.path"
      v-for="p in noChild"
      :key="p.id"
      :index="p.id"
      @click="getBread(p.label, p.path)"
    >
      <i :class="`el-icon-${p.icon}`"></i>
      <span>{{ p.label }}</span>
    </el-menu-item>
    <el-submenu :index="p.id" v-for="p in hasChild" :key="p.id">
      <template slot="title">
        <i :class="`el-icon-${p.icon}`"></i>
        <span>{{ p.label }}</span>
      </template>
      <el-menu-item
        :route="m.path"
        v-for="m in p.children"
        :key="m.id"
        :index="m.id"
        @click="getBread(m.label, m.path)"
      >
        <i :class="`el-icon-${m.icon}`"></i>
        <span>{{ m.label }}</span>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "ComAside",
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    handleOpen(key, keyid) {
      // console.log(key+':'+ keyid);
    },
    handleClose(key, keyid) {
      // console.log(key+':' +keyid);
    },
    getBread(name, path) {
      this.$store.dispatch("bread/getBreadData", { name, path });
    },
  },
  computed: {
    ...mapState("navLeft", ["navData"]),
    noChild() {
      return this.navData.filter((p) => !p.children);
    },
    hasChild() {
      return this.navData.filter((p) => p.children);
    },
  },
  mounted() {
    this.$store.dispatch("navLeft/getNavData");
    this.$bus.$on("xCollapse", (value) => {
      this.isCollapse = value;
    });
    // console.log(this.$route);
  },
};
</script>

<style lang='less' scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  height: 100%;
  border: none;
  .el-submenu {
    .el-menu-item {
      margin-left: 0;
    }
  }

  h3 {
    color: white;
    line-height: 60px;
    text-align: center;
  }
}
.el-menu-vertical-demo {
  height: 100%;
  border: 0;
  h3 {
    color: white;
    line-height: 60px;
    text-align: center;
  }
}
</style>